#include<iostream>
using namespace std;
int main() {
	int num, k, count;
	cin >> num >> k;
	int arr0[100], arr1[100];
	arr0[0] = 1, arr1[0] = k - 1;
	for (int i = 1; i < num; i++) {
		arr0[i] = arr1[i - 1];
		arr1[i] = (k - 1)*(arr0[i-1] + arr1[i - 1]);
		count = i;
	}
	cout << arr1[count] << endl;
}